#include<stdio.h>
#include<iostream>
using namespace std;
const int maxn = 15;
struct poly{
    int count;
    double coef[maxn];
    int expo[maxn];
};

void input(struct poly &polyCase)
{
    int k;
    cin>>k;
    polyCase.count = k;
    for(int i = 0; i < k; i++) {
        int tempExpo;
        double tempCoef;
        cin>>tempExpo>>tempCoef;
        polyCase.expo[i] = tempExpo;
        polyCase.coef[i] = tempCoef;
    }
}

int main(void)
{
    struct poly poly1;
    struct poly poly2;
    input(poly1);
    input(poly2); 
    int p1=0,p2=0,pRes=0;
    struct poly result;
    result.count = 0;
    while(p1<poly1.count&&p2<poly2.count) {
       if(poly1.expo[p1] > poly2.expo[p2]) {
            result.expo[pRes] = poly1.expo[p1];
            result.coef[pRes] = poly1.coef[p1];
            pRes++;p1++;result.count++;     
        } 
        else if(poly1.expo[p1] < poly2.expo[p2]){
            result.expo[pRes] = poly2.expo[p2];
            result.coef[pRes] = poly2.coef[p2];
            pRes++;p2++;result.count++;
        }
        else{
            double sumCoef = poly1.coef[p1]+poly2.coef[p2];
            if(sumCoef!=0) {
                result.expo[pRes] = poly1.expo[p1];
                result.coef[pRes] = sumCoef;
                pRes++;result.count++;
            }
            p1++;p2++;
            
        }
    }
    while(p1<poly1.count) {
        result.expo[pRes] = poly1.expo[p1]; 
        result.coef[pRes] = poly1.coef[p1];
        pRes++;p1++;result.count++; 
    }
    while(p2<poly2.count) {
        result.expo[pRes] = poly2.expo[p2];
        result.coef[pRes] = poly2.coef[p2];
        pRes++;p2++;result.count++;
    }
    printf("%d",result.count);
    for(int i=0; i < result.count; i++) {
        printf(" %d",result.expo[i]);
        printf(" %.1f",result.coef[i]);
    }
    return 0;
}